package com.kelvin.paopao.module.person.photoset;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.Toolbar;
import android.view.View;

import com.kelvin.paopao.R;
import com.kelvin.paopao.adapter.PhotoSetAdapter;
import com.kelvin.paopao.module.base.BaseActivity;
import com.kelvin.paopao.widgets.PhotoViewPager;

import java.io.Serializable;
import java.util.List;

import butterknife.BindView;

/**
 * Created by MCK on 2017/5/18.
 */

public class PhotoSetActivity extends BaseActivity {
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.viewPager)
    PhotoViewPager viewPager;
    private List<String> urls;

    private PhotoSetAdapter adapter;
    private int position;

    private boolean mIsHideToolbar;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_photo_set;
    }

    @Override
    protected void initInjector() {

    }

    @Override
    protected void initViews() {
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        urls = (List<String>) getIntent().getSerializableExtra("urls");
        position = getIntent().getIntExtra("position", 0);
        adapter = new PhotoSetAdapter(this, urls);
        adapter.setTapListener(new PhotoSetAdapter.OnTapListener() {
            @Override
            public void onPhotoClick() {
                mIsHideToolbar = !mIsHideToolbar;
                if (mIsHideToolbar) {
                    toolbar.animate().translationY(-toolbar.getBottom()).setDuration(300);
                } else {
                    toolbar.animate().translationY(0).setDuration(300);
                }
            }
        });

        viewPager.setAdapter(adapter);
        viewPager.setOffscreenPageLimit(urls.size());

        viewPager.setCurrentItem(position);
    }

    @Override
    protected void updateViews(boolean isRefresh) {

    }

    public static void launch(Context context, List<String> urls, int position) {
        Intent intent = new Intent(context, PhotoSetActivity.class);
        intent.putExtra("urls", (Serializable) urls);
        intent.putExtra("position", position);
        context.startActivity(intent);
    }
}
